<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;
/**
 * Class EntryController
 * @package App\Http\Controllers\Admin
 */
class EntryController extends Controller
{

    //
    /**
     * EntryController constructor.
     */
    public function __construct()
    {
        $this->middleware('admin.auth')->except(['loginForm', 'login']);
    }

    public function index(){
        return view('admin.entry.index');
//        return '后台index';
    }
    /**
     * 登陆视图
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function loginForm(){
        return view('admin.entry.login');
//        return 'asdasdfas';
    }

    /**
     *
     */
    public function login(Request $request) {

//        return view('admin.entry.index');
        $status = Auth::guard('admin')->attempt([
            'username' => $request->input('username'),
            'password' => $request->input('password'),
        ]);
//        dd($status);
        if ($status){
            //登陆成功
            return redirect('admin/index');
        }
        return redirect('admin/login')->with('error', '用户名或密码错误');
    }

    /**
     * 退出登录
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function logout()
    {
        Auth::guard('admin')->logout();

        return redirect('/admin/login');
    }

}
